package Thread_lock;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/29
 * Time:17:50
 * 线程不安全示例
 **/
public class Demo1 {

    private static int count = 0;
    //最大循环次数
    public static final int MAXSIZE = 10_0000;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < MAXSIZE; i++) {
                    count++;
                }
            }
        });
        t1.start();

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < MAXSIZE; i++) {
                    count--;
                }
            }
        });
        t2.start();

        t1.join();
        t2.join();

        System.out.println(count);
    }
}
